const http = require("http");
const fs = require("fs");
const path = require("path");
const { URL } = require("url");
http.createServer((req, res) => {
    switch (req.method) {
        case "GET":
            getResource(req, res);
            break;
        case "POST":
            postData(req, res);
            break;
        case "DELETE":
            deleteData(req, res);
            break;
        case "PUT":
            updateData(req, res);
            break;
    }

}).listen(8080);
function getResource(req, res) {
    let fileContent = fs.readFileSync('fankui.html')
    res.end(fileContent)
}
function postData(req, res) {
    let str = "";
    req.on("data", (chunk) => {
        str += chunk;
    })
    req.on("end", () => {
        console.log(str);//{"username":"zhangsan"}  从服务端传到客户端
        res.end(req.method);//传到服务端  在控制台输出POST
    })

    res.end(req.method)
}
function deleteData(req, res) {
    res.end(req.method);
}
function updateData(req, res) {
    res.end(req.method)
}
console.log("server is listening 8080")